import br.com.jambu.cge.*

class BootStrap {
	def fixtureLoader
	def fixturesEnabled

    def init = { servletContext ->
		log.info "Fixtures: ${fixturesEnabled}"
		for(String s in fixturesEnabled) {
			loadFixture(s)
		}
    }
    def destroy = {
    }
	
	def loadFixture(s){
		if(!FixtureRegister.findByName(s.toUpperCase())) {
			log.info "Loading fixture ${s}..."
			fixtureLoader.load(s.toLowerCase())
			def f=new FixtureRegister(name:s.toUpperCase())
			if (!f.save(flush:true)) {
				log.debug "Erro ao salvar Fixture Register"
				f.errors.allErrors.each {
					log.debug it
				}
			}
		}
	}

}
